import requests
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
import sys

''' 注意 可能需要关闭本地的梯子才能成功运行  我测试的时候因为本机开了Clash 所以一直失败 '''

# ads_id是你想要启动的指纹浏览器 账号id   注意不是序号 注册ads后新建一个浏览器 把id填在这里即可使用
ads_id = "jhkilmi"
open_url = "http://local.adspower.com:50325/api/v1/browser/start?user_id=" + ads_id
close_url = "http://local.adspower.com:50325/api/v1/browser/stop?user_id=" + ads_id

resp = requests.get(open_url).json()
print(resp)
if resp["code"] != 0:
    print(resp["msg"])
    print("please check ads_id")
    sys.exit()

chrome_driver = resp["data"]["webdriver"]
service = Service(executable_path=chrome_driver)
chrome_options = Options()

chrome_options.add_experimental_option("debuggerAddress", resp["data"]["ws"]["selenium"])
driver = webdriver.Chrome(service=service, options=chrome_options)

print(driver.title)
driver.get("https://www.baidu.com/")
time.sleep(2)

# test
inputText = driver.find_element(By.CLASS_NAME, "s_ipt")
inputText.send_keys("bitcoin")
time.sleep(1)

# 关闭指纹浏览器
# driver.quit()
# requests.get(close_url)
